import {
  getToken,
  setToken,
  removeToken,
  setRememberPassword,
} from "../utils/auth/auth";

const state = {
  rememberPaeeword: "",
  token: getToken(),
  email: "",
  password: "",
  remember: "",
  magmap: false,
  lesmap: false,
  status: 0,
  lastLoginTime: "",
  isAdminLoggedIn: "",
  userId: "",
  searchWord: "",
  roleid: "",
};

const mutations = {
  setToken(state, token) {
    state.token = token;

    setToken(token);
  },
  setEmail(state, email) {
    state.email = email;
    localStorage.setItem("email", email);
  },
  setPassword(state, password) {
    state.password = password;
  },
  setStatus(state) {
    state.status = 1;
  },

  removeToken(state) {
    state.token = null;
    removeToken();
  },

  setRememberPassword(state, rememberPaeeword) {
    state.rememberPaeeword = rememberPaeeword;
    setRememberPassword(rememberPaeeword);
  },

  //设置登录时间
  setLastLoginTime(state, time) {
    state.lastLoginTime = time;
    console.log("time", time);
    localStorage.setItem("loginTime", state.lastLoginTime);
  },
  setCharacter(state, character) {
    state.roleid = character;
  },
  setUserId(state, id) {
    state.userId = id;
  },
  setSearchWord(state, keyword) {
    state.searchWord = keyword;
  },
};

const actions = {};

const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
